package com.wgke.bluetooth.beans;

import java.util.List;

public class CommandBean {
    public String name;
    public String cmd;
    public String scope;
    public String doc;
    public String type;
    public int value;
    public List<CommandBean> params;


    public String getCrc(byte[] buf) {
        int crc = 0xFFFF;
        for (byte b : buf) {
            crc ^= (b & 0xFF);
            for (int i = 0; i < 8; i++) {
                if ((crc & 1) != 0) {
                    crc >>= 1;
                    crc ^= 0xA001;
                } else {
                    crc >>= 1;
                }
            }
        }
        return bytesToHex(new byte[]{(byte) (crc & 0xFF), (byte) ((crc >> 8) & 0xFF)});
    }

    public String bytesToHex(byte[] bytes) {
        StringBuilder hexBuilder = new StringBuilder();
        for (byte b : bytes) {
            // 方法1：使用 String.format（推荐）
            hexBuilder.append(String.format("%02X", b));
        }
        return hexBuilder.toString();
    }
}
